package com.yuyakaido.android.cardstackview.sample;

import android.util.Log;
import android.view.MotionEvent;

/**
 * User: newSalton@outlook.com
 * Date: 2019/11/23 16:55
 * ModifyTime: 16:55
 * Description:
 */
public class TouchEventUtil {
    public static void logActionMsg(Class cls, String functionName, MotionEvent ev) {
        logActionMsg(cls, functionName, ev, "noMsg");
    }

    enum LogType {
        Down, Up, Move, All
    }

    static LogType mLogType = LogType.Down;


    public static void logActionMsg(Class cls, String functionName, MotionEvent ev, String msg) {
        switch (mLogType) {
            case Down:
                if (ev.getAction() == MotionEvent.ACTION_DOWN)
                    doPrint(cls, functionName, ev, msg);
                break;
            case Up:
                if (ev.getAction() == MotionEvent.ACTION_UP)
                    doPrint(cls, functionName, ev, msg);
                break;
            case Move:
                if (ev.getAction() == MotionEvent.ACTION_MOVE)
                    doPrint(cls, functionName, ev, msg);
                break;
            case All:
                doPrint(cls, functionName, ev, msg);
                break;
            default:
                break;
        }
    }

    private static void doPrint(Class cls, String functionName, MotionEvent ev, String msg) {
        Log.e("newsaltontouch", cls.getSimpleName() + "\t----\t" + functionName + "\t---->\t" + getTouchAction(ev.getAction()) + "\t---->\t" + msg);
    }

    private static String getTouchAction(int actionId) {
        String actionName = "Unknow:id=" + actionId;
        switch (actionId) {
            case MotionEvent.ACTION_DOWN:
                actionName = "ACTION_DOWN";
                break;
            case MotionEvent.ACTION_MOVE:
                actionName = "ACTION_MOVE";
                break;
            case MotionEvent.ACTION_UP:
                actionName = "ACTION_UP";
                break;
            case MotionEvent.ACTION_CANCEL:
                actionName = "ACTION_CANCEL";
                break;
            case MotionEvent.ACTION_OUTSIDE:
                actionName = "ACTION_OUTSIDE";
                break;
        }
        return actionName;
    }

    public static void doClick(Class cls){
        Log.e("【click】", cls.getSimpleName() + " is  clicked!!");
    }

}
